package com.atguigu.util.method_son;

/**
 * @author caesar
 * @date 2025/7/7
 * @Description:
 * @apiNote
 */
public class Point {
    private final double x;
    private final double y;

    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    // 计算到原点 (0, 0) 的距离
    public double distanceToOrigin() {
        return Math.sqrt(x * x + y * y);
    }

    // 计算到另一个点的距离
    public double distanceTo(Point other) {
        double dx = this.x - other.x;
        double dy = this.y - other.y;
        return Math.sqrt(dx * dx + dy * dy);
    }

    @Override
    public String toString() {
        return "Point[x=" + x + ", y=" + y + "]";
    }
}
